﻿package com.javaPattern.Mediator;

import java.util.ArrayList;
import java.util.List;

public class ConcreteMediator extends Mediator {

	private List<Colleague> colleagues = new ArrayList<Colleague>(0);

	public void addCollegue(Colleague colleague) {
		colleagues.add(colleague);
	}

	public void action(Colleague actor) {
		String msg = actor.getMessage();
		
		// send msg
		for (Colleague colleague : colleagues) {
			if (colleague.equals(actor)) {
				colleague.sendMsg();
				break;
			}
		}

		// got msg
		for (Colleague colleague : colleagues) {
			if (colleague.equals(actor))
				continue;
			else
			colleague.getMsg(msg);
		}
	}
}
